#define _CRT_SECURE_NO_WARNINGS 1

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 100100;
ll arr[N], a[N];

int main()
{
	ll n;
	cin >> n;
	ll ans = 0;

	for (ll i = 0; i < n; i++)
		cin >> arr[i];
	for (ll i = 0; i < n / 2; i++)
		a[i] = arr[n - 1 - i] - arr[i];

	for (ll i = 0; i < n / 2; i++)
	{
		ans += abs(a[i]);
		if (a[i] * a[i + 1] > 0)
			if (abs(a[i + 1]) > abs(a[i])) a[i + 1] -= a[i];
			else  i++;
	}

	cout << ans << endl;

	return 0;
}